/* eslint-disable prettier/prettier */
const fs = require('fs');
const path = require('path');

// 指定你的PNG文件夹路径
const pngDir = path.join(__dirname, '../src/image/practice');
// 输出文件的路径
const outputFilePath = path.join(__dirname, './Pngs.js');

// 读取目录中的所有文件
fs.readdir(pngDir, (err, files) => {
  if (err) {
    console.error('Error reading directory', err);
    return;
  }

  let importStatements = '';

  // 遍历文件并构建import语句
  files.forEach(file => {
    if (path.extname(file) === '.png') {
      const fileName = path.basename(file, '.png');
      importStatements += `import ${fileName} from './${file}';\n`;
    }
  });

  // 将import语句写入Pngs.js文件
  fs.writeFile(outputFilePath, importStatements, err => {
    if (err) {
      console.error('Error writing file', err);
      return;
    }
    console.log('Pngs.js file has been created successfully.');
  });
});